# Maintainer: Yusuke Sasaki <yusuke.sasaki.nuem@gmail.com>

_realname=msgpack-c
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.3.0
pkgrel=1
pkgdesc="MessagePack implementation for C and C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/msgpack/msgpack-c"
license=('custom:Boost Software License 1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-gtest"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-zlib")
depends=()
source=("https://github.com/msgpack/msgpack-c/releases/download/cpp-${pkgver}/msgpack-${pkgver}.tar.gz")
sha256sums=('6e114d12a5ddb8cb11f669f83f32246e484a8addd0ce93f274996f1941c1f07b')

build() {
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL='-DCMAKE_INSTALL_PREFIX=' \
    ${MINGW_PREFIX}/bin/cmake \
      -G "MSYS Makefiles" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      ${extra_config} \
      -DMSGPACK_CXX11=ON \
      -DMSGPACK_BUILD_EXAMPLES=OFF \
      -DMSGPACK_BUILD_TESTS=OFF \
      ../msgpack-${pkgver}
  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make test || true
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/msgpack-${pkgver}/LICENSE_1_0.txt ${okgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_1_0.txt
}
